package com.wanxi.controller.front;

import com.wanxi.domain.ResultModel;
import com.wanxi.domain.front.FootInfoModel;
import com.wanxi.domain.front.TopInfoModel;
import com.wanxi.domain.front.TopNavModel;
import com.wanxi.domain.product.ProductModel;
import com.wanxi.service.front.HomeService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RequestMapping("font")
@RestController
@CrossOrigin(allowCredentials = "true", origins = "http://localhost:63342", allowedHeaders = "*")//允许跨域请求
public class HomeController {

    @Autowired
    HomeService homeService;

    /*设置顶部信息*/
    @GetMapping("topInfo")
    public List<TopInfoModel> getTopInfo(){
        List<TopInfoModel> topInfo = homeService.getTopInfo();
        return topInfo;

    }

    /*设置首页导航栏信息*/
    @GetMapping("nav")
    public  List<TopNavModel>  getNavInfo(){
        List<TopNavModel>  navInfo = homeService.getNavInfo();

        return navInfo;

    }
    /*新增导航*/
    @PostMapping("insertNav")
    public int insertNav(@RequestBody TopNavModel topNavModel){

        int resultModel = homeService.insertNav(topNavModel);

        return resultModel;

    }
    /*根据id删除产品*/
    @PostMapping("deleteNav")
    public int deleteNavByTitle(@RequestBody TopNavModel topNavModel){

        int resultModel =  homeService.deleteNavByTitle(topNavModel.getId());

        return resultModel;

    }

    /*设置首页底部信息*/
    @GetMapping("footInfo")
    public List<FootInfoModel> getFootInfo(){
        List<FootInfoModel> resultModel =  homeService.getFootInfo();
        return resultModel;
    }
    /*新增产品*/
    @PostMapping("insertFoot")
    public int insertFoot(@RequestBody FootInfoModel footInfoModel){

        int resultModel = homeService.insertFoot(footInfoModel);

        return resultModel;

    }
    /*根据id删除产品*/
    @PostMapping("deleteFoot")
    public int deleteFootByTitle(@RequestBody FootInfoModel footInfoModel){

        int resultModel =  homeService.deleteFootByTitle(footInfoModel.getId());

        return resultModel;

    }
    /*编辑导航栏*/
    @PostMapping("updateNav")
    public int updateProduct(@RequestBody TopNavModel navModel){

        int resultModel =  homeService.updateNav(navModel);


        return resultModel;

    }
    /*编辑导航栏*/
    @PostMapping("updateFoot")
    public int updateProduct(@RequestBody FootInfoModel footInfoModel){

        int resultModel =  homeService.updateFoot(footInfoModel);


        return resultModel;

    }
    /*根据产品id查新产品信息*/
    @GetMapping("findNavById")
    public TopNavModel findNavById(@Param("id") Integer id){

        TopNavModel resultModel = homeService.findNavById(id);

        return resultModel;

    }
    @GetMapping("findFootById")
    public FootInfoModel findFootById(@Param("id") Integer id){

        FootInfoModel resultModel = homeService.findFootById(id);

        return resultModel;

    }




}
